import unittest
from searchEngineTool import search_engine_tool

class TestSearchEngineTool(unittest.TestCase):
    def test_google_search(self):
        query = "深圳天气"
        engine = "google"
        results = search_engine_tool(query, engine)
        self.assertEqual(len(results), 5)
        for result in results:
            self.assertIn("href", result)
            self.assertIn("title", result)
            self.assertIn("abstract", result)
            self.assertNotEqual(result["href"], "")
            self.assertNotEqual(result["title"], "")
            self.assertNotEqual(result["abstract"], "")

    def test_bing_search(self):
        query = "深圳天气"
        engine = "bing"
        results = search_engine_tool(query, engine)
        self.assertEqual(len(results), 5)
        for result in results:
            self.assertIn("href", result)
            self.assertIn("title", result)
            self.assertIn("abstract", result)
            self.assertNotEqual(result["href"], "")
            self.assertNotEqual(result["title"], "")
            self.assertNotEqual(result["abstract"], "")

    def test_yahoo_search(self):
        query = "深圳天气"
        engine = "yahoo"
        results = search_engine_tool(query, engine)
        self.assertEqual(len(results), 5)
        for result in results:
            self.assertIn("href", result)
            self.assertIn("title", result)
            self.assertIn("abstract", result)
            self.assertNotEqual(result["href"], "")
            self.assertNotEqual(result["title"], "")
            self.assertNotEqual(result["abstract"], "")

    def test_duckduckgo_search(self):
        query = "深圳天气"
        engine = "duckduckgo"
        results = search_engine_tool(query, engine)
        self.assertEqual(len(results), 5)
        for result in results:
            self.assertIn("href", result)
            self.assertIn("title", result)
            self.assertIn("abstract", result)
            self.assertNotEqual(result["href"], "")
            self.assertNotEqual(result["title"], "")
            self.assertNotEqual(result["abstract"], "")

    def test_invalid_search_engine(self):
        query = "test query"
        engine = "invalid_engine"
        with self.assertRaises(ValueError):
            search_engine_tool(query, engine)

if __name__ == '__main__':
    unittest.main()
